#include<bits/stdc++.h>
using namespace std;
int n[200005];
int a,b,c,d,e;
int dfs(int x,int y,int z){
	if(z>b){
		return 0;
	}
	int u=0,v=0;
	if(n[z]==n[x] and x!=0) u=n[z];
	if(n[z]==n[y] and y!=0) v=n[z];
	return max(dfs(z,y,z+1)+u,dfs(x,z,z+1)+v);
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>a;
	for(int i=1;i<=a;i++){
		cin>>b;
		for(int j=1;j<=b;j++){
			cin>>n[j];
		}
		cout<<dfs(0,0,1)<<endl;
	}
	return 0;
}
